require 'web_scraper'
require 'dummy_scraper'
require 'plain_writer'
require 'xml_writer'
require 'arguments_parser'

args = ARGV

#~ args = %w{l -m -p -odata.xml -i wang-p06,876143 -b gmail,wangpengtest1,starfire,gmail,wangpengtest4,starfire,yahoo,wangpengtest2@yahoo.com.cn,starfire,yahoo,wangpengtest3@yahoo.cn,starfire,tsinghua,wang-p06,876143,}

options = ArgumentsParser.parse(args) or exit(1)

if options[:use_dummy]
  scraper = DummyScraper.new
else
  scraper = WebScraper.new
end

if options[:learn_enabled] 
  courses = scraper.scrape_courses(options[:learn_username], options[:learn_password])
else
  courses = []
end

if options[:mail_enabled]
  mailboxes = scraper.scrape_mailboxes(options[:mailboxes])
else
  mailboxes = []
end

if options[:plain_text]
  writer = PlainWriter.new
else
  writer = XmlWriter.new
end

if options[:data_file_name] and options[:data_file_name] != ""
  writer.write_to_file(options[:data_file_name], courses, mailboxes)
end
